package com.yfp.client.util;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;
import java.util.Optional;

/**
 * 设备返回实体
 * @param <T>
 */
@Data
@AllArgsConstructor
public class DeviceResponse<T> implements Serializable {
    // 状态
    private String status;
    //
    private String message;
    // 数据
    private Optional<T> payload;

    public static <T> DeviceResponse<T> success(){
      return  new DeviceResponse<>(
                DeviceErrorCode.SUCCESS,
                "Success",
                Optional.empty()
        );
    }

    public static <T> DeviceResponse<T> success(T payload){
        return new DeviceResponse<>(
                DeviceErrorCode.SUCCESS,
                "Success",
                Optional.ofNullable(payload)
        );
    }

    public static <T> DeviceResponse<T> failuer() {
        return  new DeviceResponse<>(
                DeviceErrorCode.FUNCTIONAL_MODULE_ERROR,
                "The system is busy",
                Optional.empty()
        );
    }
    public static <T> DeviceResponse<T> failuer(String deviceErrorCode) {
        return  new DeviceResponse<>(
                deviceErrorCode,
                "The system is busy",
                Optional.empty()
        );
    }
}
